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AL2iO1c9ea0qk/o37QygVYi09+wkrYghISKdVCmSdoGHH
6XKtZQpcZpCQtfu/XTt8nysmsDgWmervjj//LhUW1w==
-----END RSA PRIVATE KEY-----`;

const encrypt = new JsEncrypt();
encrypt.setPublicKey(PUBLIC_KEY);
encrypt.setPrivateKey(PRIVATE_KEY);

const getParams = () => {
    let tail = window.location.search;
    const params = {};
    if (tail === '') {
        return null;
    } else {
        tail = tail.slice(1);
        tail = tail.split('&');
        let temp;
        for (let i = 0, len = tail.length; i < len; i++) {
            temp = tail[i].split('=');
            // eslint-disable-next-line prefer-destructuring
            params[temp[0]] = temp[1];
        }
        temp = null;
    }
    return params
}

export {
    getParams,
    encrypt
};
